import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-face-detect',
  templateUrl: './face-detect.component.html',
  styleUrls: ['./face-detect.component.css']
})
export class FaceDetectComponent implements OnInit {

  constructor() {
  }
  
  ngOnInit() {
    this.startVideo();
  }
  
  public startVideo() {
    var video = <HTMLVideoElement> document.getElementById('video');
    if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
      navigator.mediaDevices.getUserMedia({video:true}).then(function (stream) {
        video.src = window.URL.createObjectURL(stream);
        video.play();
      });
    }
  }
  
  public snapshot() {
    var video = <HTMLVideoElement> document.getElementById('video');
    var canvas = <HTMLCanvasElement> document.getElementById('canvas');
    var context = canvas.getContext('2d');
    context.drawImage(video, 0, 0, 640, 480);
    var data = <ImageData> context.getImageData(0,0,640,480);
    console.log(data.data);
  }

  public sleep(miliseconds) {
    setTimeout(function() {
      
    }, miliseconds);
  }

}
